var mongo = require('./lib/mongodb'),
  Db		= mongo.Db,
	Connection	= mongo.Connection,
	Server		= mongo.Server,
	Cursor		= mongo.Cursor,
	BSON		= mongo.BSONNative;

var dbh = new Db("test", new Server("127.0.0.1", 27017, {}), {native_parser:false, strict: true});
dbh.open(function(err,db) {
	if ( err ) {
		console.log("Error connecting to database");
		process.exit(0);
	}

	console.log("Running");

	db.collection("news",function(err,col) {
		if(err) {
			console.log("Error getting collection");
			process.exit(1);
		}

		var runQuery = function() {
			return col.find({},{limit:10},function(err,cursor){
				if ( err ) {
					console.log("Error finding data");
					process.exit(2);
				}
				return cursor.each(function(err,row){
					if ( row == null )
						process.nextTick(runQuery);
				});
			});
		};
		runQuery();
	});
});